# -*- coding: UTF-8 -*-
# __author__ = '10459'
from app.libs.enums import PendingStatus
from app.models.base import Base
from sqlalchemy import Column, Integer, String, Boolean, Float,ForeignKey,desc,func, SmallInteger
from sqlalchemy.orm import relationship


class Drift(Base):
    """
    一次具体交易的信息
    """
    id = Column(Integer,primary_key=True)
    #邮寄信息
    recipient_name = Column(String(20),nullable=False)
    address = Column(String(100),nullable=False)
    message = Column(String(200))
    mobile = Column(String(20),nullable=False)

    #书籍信息
    isbn = Column(String(13))
    book_title = Column(String(50))
    book_author = Column(String(30))
    book_img = Column(String(50))

    #请求者信息
    requester_id = Column(Integer)
    requester_nickname =Column(String(20))

    #赠送者的信息,gift_id当前这次交易礼物的id号
    gifter_id = Column(Integer)
    gift_id =Column(Integer)
    gifter_nickname=Column(String(20))
#鱼漂的状态,利用数字表示状态没有好的已读性，所以使用枚举enums
    _pending = Column('pending',SmallInteger,default=1)
    #类似参数传入枚举值构造函数里面,将数字转换成枚举
    @property
    def pending(self):
        return PendingStatus(self._pending)
    #把枚举转换成数字
    @pending.setter
    def pending(self,status):
        self._pending = status.value

#历史记录没必要关联模型，因为是历史信息，不需要实时同步这个东西，有些场景不需要，比如淘宝价格，假如关联就坑爹了
#会误导用户
    # requester_id = Column(Integer,ForeignKey('requester.id'))
    # requester =relationship('User')
    # gift_id =Column(Integer,ForeignKey('gift.id'))
    # gift = relationship("Gift")
